package com.ruoyi.web.controller.vis;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.vis.domain.reg.SysPatient;
import com.ruoyi.system.vis.service.reg.SysPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vis/reg")
public class SysPatientController extends BaseController {

    @Autowired
    private SysPatientService sysPatientService;



    //    查询患者信息
    @GetMapping(path = "/{patientCard}")
    public AjaxResult list(@PathVariable String patientCard){

        SysPatient sysPatient = sysPatientService.selectPatientByCard(patientCard);

        if (sysPatient==null){
            return AjaxResult.error("未查询到该患者信息，请手动加载");
        }

        return AjaxResult.success(sysPatient);

    }

    @PostMapping
    public AjaxResult add(@RequestBody SysPatient patient){


        if (sysPatientService.selectPatientByCard(patient.getPatientCard())!=null)
        {
            return AjaxResult.error("新增患者'" + patient.getPatientCard() + "'失败，患者已存在");
        }

        patient.setPatientCard(patient.getPatientCard());


        sysPatientService.insertPatient(patient);

        return AjaxResult.success("操作成功",patient);
    }

}
